import java.io.IOException;
import java.net.Socket;

public class MonitoringServer extends Server implements ClientListener {
	
	
    /**
     * Creates a new Monitoring Server.
     */
	public MonitoringServer(int port) throws IOException {
		super(port);
	}

	@Override
	public Client clientConnected(Socket clientSocket) throws IOException {
		Client client = new SimClient(this, clientSocket);
		
		client.addMessageListener(this);
		
		System.out.println("New Client Connected: "+client.getInetAddress());
		
		return client;
	}
	
	@Override
	public void clientDisconnected(Client client) {
		System.out.println("Client Disconnected: "+client.getInetAddress());
	}

	@Override
	public void messageRecieved(Client source, String message) {
		// If the client has sent a termination message then disconnect them.
		if(Messages.TERMINATION.matcher(message).matches())
			disconnect(source);
	}

}
